Boost
boost
arrow_drop_down
Boost.Math
C++ 14 Added in Boost 1.29.0
Categories: Math

Boost.Math includes several contributions in the domain of mathematics: Floating Point Utilities, Specific Width Floating Point Types, Mathematical Constants, Statistical Distributions, Special Functions, Root Finding and Function Minimization, Polynomials and Rational Functions, Interpolation, and Numerical Integration and Differentiation. Many of these features are templated to support both built-in, and extended width types (e.g. Boost.Multiprecision)

This Release

various
Author
John Maddock
John Maddock
Maintainer
Chris Kormanyos
Chris Kormanyos
Maintainer
Nick Thompson
Nick Thompson
Maintainer
Matt Borland
Matt Borland
Maintainer
Alejandro Baranek
Alejandro Baranek
Contributor - New
Lukas Riebel
Lukas Riebel
Contributor - New
Rene Rivera
Rene Rivera
Contributor

Boost Math Library

ANNOUNCEMENT: This library requires a compliant C++14 compiler.

Master Develop
Drone Build Status Build Status
Github Actions Build Status Build Status
Codecov codecov codecov

The Math library provides numerous advanced mathematical functions implemented in modern C++. The library strives to deliver the utmost in numerical and syntactical correctness while still maintaining high-performance.

All code is header-only, facilitating easy client setup and use throughout the entire diverse collection of functions.

The library is divided into several interconnected parts:

Floating Point Utilities

Utility functions for dealing with floating point arithmetic, includes functions for floating point classification (fpclassify, isnan, isinf etc), sign manipulation, rounding, comparison, and computing the distance between floating point numbers.

Specific Width Floating Point Types

A set of typedefs similar to those provided by <cstdint> but for floating point types.

Mathematical Constants

A wide range of constants ranging from various multiples of π, fractions, Euler's constant, etc.

These are of course usable from template code, or as non-templates with a simplified interface if that is more appropriate.

Statistical Distributions

Provides a reasonably comprehensive set of statistical distributions, upon which higher level statistical tests can be built.

The initial focus is on the central univariate distributions. Both continuous (like normal & Fisher) and discrete (like binomial & Poisson) distributions are provided.

A comprehensive tutorial is provided, along with a series of worked examples illustrating how the library is used to conduct statistical tests.

Special Functions

Provides a wide range of high quality special functions; initially these were concentrated on functions used in statistical applications along with those in the Technical Report on C++ Library Extensions.

The function families currently implemented are the gamma, beta and error functions along with the incomplete gamma and beta functions (four variants of each) and all the possible inverses of these, plus the digamma, various factorial functions, Bessel functions, elliptic integrals, hypergeometrics, sinus cardinals (along with their hyperbolic variants), inverse hyperbolic functions, Legrendre/Laguerre/Hermite/Chebyshev polynomials and various special power and logarithmic functions.

All the implementations are fully generic and support the use of arbitrary "real-number" types, including those in Boost.Multiprecision. Most functions are, however, optimized for use with types with known significand (or mantissa) sizes: typically built-in float, double or long double.

These functions also provide the basis of support for the TR1 special functions, many of which became standardized in C++17.

Root Finding

A comprehensive set of root-finding algorithms over the real line, both with derivatives and derivative free.

Optimization

Minimization of cost functions via Brent's method and differential evolution.

Polynomials and Rational Functions

Tools for manipulating polynomials and for efficient evaluation of rationals or polynomials.

Interpolation

Function interpolation via barycentric rational interpolation, compactly supported quadratic, cubic, and quintic B-splines, the Chebyshev transform, trigonometric polynomials, Makima, pchip, cubic Hermite splines, and bilinear interpolation.

Numerical Integration and Differentiation

A reasonably comprehensive set of routines for integration (trapezoidal, Gauss-Legendre, Gauss-Kronrod, Gauss-Chebyshev, double-exponential, and Monte-Carlo) and differentiation (Chebyshev transform, finite difference, the complex step derivative, and forward-mode automatic differentiation).

The integration routines are usable for functions returning complex results - and hence can be used for computation of contour integrals.

Quaternions and Octonions

Quaternion and Octonion are class templates similar to std::complex.

The full documentation is available on boost.org.

Standalone Mode

Defining BOOST_MATH_STANDALONE allows Boost.Math to be used without any Boost dependencies. Some functionality is reduced in this mode. A static_assert message will alert you if a particular feature has been disabled by standalone mode. Standalone mode is not designed to be used with the rest of boost, and may result in compiler errors.

Supported Compilers

The following compilers are tested with the CI system, and are known to work. Currently a compiler that is fully compliant with C++14 is required to use Boost.Math.

  • g++ 5 or later
  • clang++ 5 or later
  • Visual Studio 2015 (14.0) or later

Support, bugs and feature requests

Bugs and feature requests can be reported through the GitHub issue tracker (see open issues and closed issues).

You can submit your changes through a pull request.

There is no mailing-list specific to Boost Math, although you can use the general-purpose Boost mailing-list using the tag [math].

Development

Clone the whole boost project, which includes the individual Boost projects as submodules (see boost+git doc):

$ git clone https://github.com/boostorg/boost
$ cd boost
$ git submodule update --init

The Boost Math Library is located in libs/math/.

Running tests

First, make sure you are in libs/math/test. You can either run all the tests listed in Jamfile.v2 or run a single test:

test$ ../../../b2                        <- run all tests
test$ ../../../b2 static_assert_test     <- single test
test$ # A more advanced syntax, demoing various options for building the tests:
test$ ../../../b2 -a -j2 -q --reconfigure toolset=clang cxxflags="--std=c++14 -fsanitize=address -fsanitize=undefined" linkflags="-fsanitize=undefined -fsanitize=address"

Continuous Integration

The default action for a PR or commit to a PR is for CI to run the full complement of tests. The following can be appended to the end of a commit message to modify behavior:

* [ci skip] to skip all tests
* [linux] to test using GCC Versions 5-12 and Clang Versions 5-14 on Ubuntu LTS versions 18.04-22.04.
* [apple] to test Apple Clang on the latest version of MacOS.
* [windows] to test MSVC-14.0, MSVC-14.2, MSVC-14.3, CYGWIN, and mingw on the latest version of Windows.
* [standalone] to run standalone mode compile tests
 

Building documentation

Full instructions can be found here, but to reiterate slightly:

libs/math/doc$ brew install docbook-xsl # on mac
libs/math/doc$ touch ~/user-config.jam
libs/math/doc$ # now edit so that:
libs/math/doc$ cat ~/user-config.jam
using darwin ;

using xsltproc ;

using boostbook
    : /usr/local/opt/docbook-xsl/docbook-xsl
    ;

using doxygen ;
using quickbook ;
libs/math/doc$ ../../../b2

All Time

Paul A. Bristow
Paul A. Bristow
Contributor
Nick
Nick
Contributor
Jeremy W. Murphy
Jeremy W. Murphy
Contributor
Daryle Walker
Daryle Walker
Contributor
sguazt
sguazt
Contributor
Beman Dawes
Beman Dawes
Contributor
AntonBikineev
AntonBikineev
Contributor
Matt Pulver
Matt Pulver
Contributor
Hubert Holin
Contributor
Kolya Matteo
Kolya Matteo
Contributor
nobody
Contributor
Daniel James
Daniel James
Contributor
Brian Wignall
Brian Wignall
Contributor
Douglas Gregor
Douglas Gregor
Contributor
akumta
akumta
Contributor
Peter Dimov
Peter Dimov
Contributor
Evan Miller
Evan Miller
Contributor
Rose
Rose
Contributor
Marshall Clow
Marshall Clow
Contributor
Vladimir Prus
Vladimir Prus
Contributor
Thijs van den Berg
Thijs van den Berg
Contributor
Victor Ananyev
Victor Ananyev
Contributor
Ryan
Ryan
Contributor
Benjamin Sobotta
Contributor
Gennaro Prota
Contributor
Bruno Lalande
Bruno Lalande
Contributor
Stephen Kelly
Stephen Kelly
Contributor
pulver
pulver
Contributor
Gennadiy Rozental
Gennadiy Rozental
Contributor
Nikhar Agrawal
Nikhar Agrawal
Contributor
Felix von Drigalski
Felix von Drigalski
Contributor
Troy D. Straszheim
Troy D. Straszheim
Contributor
Bryce Adelstein-Lelbach
Bryce Adelstein-Lelbach
Contributor
Suyash Patil
Suyash Patil
Contributor
Misha Bergal
Contributor
inkstink
inkstink
Contributor
Jürgen Hunold
Jürgen Hunold
Contributor
Robin Eckert
Robin Eckert
Contributor
Steven Watanabe
Steven Watanabe
Contributor
Matheus Castanho
Matheus Castanho
Contributor
Aleksey Gurtovoy
Contributor
zerotypos-found
zerotypos-found
Contributor
Lakshay Garg
Lakshay Garg
Contributor
Brian Kuhl
Brian Kuhl
Contributor
Michael A. Jackson
Michael A. Jackson
Contributor
Kohei Takahashi
Kohei Takahashi
Contributor
Edward Diener
Edward Diener
Contributor
Jan Blumschein
Jan Blumschein
Contributor
Jeremiah Willcock
Jeremiah Willcock
Contributor
Markus Schöpflin
Contributor
Nikita Kniazev
Nikita Kniazev
Contributor
sdarwin
sdarwin
Contributor
Björn Karlsson
Contributor
Andrew Sutton
Andrew Sutton
Contributor
Katrin Leinweber
Katrin Leinweber
Contributor
Jeremy Murphy
Contributor
warren
warren
Contributor
Rosen Penev
Rosen Penev
Contributor
Conor Jackson
Conor Jackson
Contributor
ambrish
ambrish
Contributor
Daniel Scharrer
Daniel Scharrer
Contributor
Matthias Koeppe
Matthias Koeppe
Contributor
Nicholas McKibben
Nicholas McKibben
Contributor
RL-S
RL-S
Contributor
Samuel Rowlinson
Samuel Rowlinson
Contributor
Jimmy Lu
Jimmy Lu
Contributor
joaquintides
joaquintides
Contributor
Fredrik Blomqvist
Contributor
Denis Kolodin
Denis Kolodin
Contributor
Kartik Mohta
Kartik Mohta
Contributor
Michael Krasnyk
Michael Krasnyk
Contributor
Alisdair Meredith
Alisdair Meredith
Contributor
Adam Wulkiewicz
Adam Wulkiewicz
Contributor
Jie
Jie
Contributor
Nick
Contributor
Jeff Garland
Jeff Garland
Contributor
Jeremy Nelson
Jeremy Nelson
Contributor
Antony Polukhin
Antony Polukhin
Contributor
Gattag
Gattag
Contributor
Eduardo García-Portugués
Eduardo García-Portugués
Contributor
markklik
markklik
Contributor
Joel de Guzman
Joel de Guzman
Contributor
Marcel Raad
Marcel Raad
Contributor
Märt Laak
Märt Laak
Contributor
Stefan Slapeta
Contributor
Andrew Johnson
Andrew Johnson
Contributor
William Ledbetter
William Ledbetter
Contributor
Dave Abrahams
Dave Abrahams
Contributor
Jonathan Turkanis
Jonathan Turkanis
Contributor
Jens Maurer
Jens Maurer
Contributor
Joachim Wuttke
Joachim Wuttke
Contributor
PRATIK AWASTHI
PRATIK AWASTHI
Contributor
Vassil Vassilev
Vassil Vassilev
Contributor
Oleg Alexandrov
Oleg Alexandrov
Contributor
Stephan T. Lavavej
Stephan T. Lavavej
Contributor
K. Noel Belcourt
K. Noel Belcourt
Contributor
kojiynet
kojiynet
Contributor
Gregory Lee
Gregory Lee
Contributor
James Folberth
James Folberth
Contributor
Daniela Engert
Daniela Engert
Contributor
Alexander Grund
Alexander Grund
Contributor
Axel Huebl
Axel Huebl
Contributor
Casey Carter
Casey Carter
Contributor
Alex Henrie
Alex Henrie
Contributor
Drew Risinger
Drew Risinger
Contributor
Eric Niebler
Eric Niebler
Contributor
Tomasz Kalisiak
Tomasz Kalisiak
Contributor
Rasmus Henningsson
Rasmus Henningsson
Contributor
Madiyar
Madiyar
Contributor
Madhur Chauhan
Madhur Chauhan
Contributor
Ralf W. Grosse-Kunstleve
Contributor
Jonathan Wakely
Jonathan Wakely
Contributor
Boris Gubenko
Contributor
Jessica Hamilton
Jessica Hamilton
Contributor
Hans Dembinski
Hans Dembinski
Contributor
EugeneZelenko
EugeneZelenko
Contributor
Rogier van Dalen
Rogier van Dalen
Contributor
Lauri Nurmi
Lauri Nurmi
Contributor